import java.util.Random;

import pulpcore.Stage;
import pulpcore.sprite.ImageSprite;

// things to do:
// make a class for scorekeeping

/**
 * The Class Token.
 */
public class Token extends ImageSprite
{
	// height of token
	/** The Constant HEIGHT. */
	private static final int HEIGHT = 10;
	// width of token
	/** The Constant WIDTH. */
	private static final int WIDTH = 10;
	/** The t direction. */
	private int tDirection = 0;
	/** The t name. */
	private String tName = "";
	/** The t point. */
	private int tPoint = 0;
	/** The t speed. */
	private double tSpeed = 0;
	
	//private int verticalstate;

	// instantiating a new token
	/**
	 * Instantiates a new token.
	 * 
	 * @param imageAsset
	 *            the image asset
	 * @param xProportion
	 *            the x proportion
	 * @param yProportion
	 *            the y proportion
	 * @param pointValue
	 *            the point value
	 */
	public Token(final String imageAsset, final int constantState, final double xProportion, final double yProportion)
	{
		// sizes images so they are all the same size
		super(imageAsset, xProportion * Stage.getWidth(), yProportion * Stage.getHeight(), WIDTH, HEIGHT);
		
		statsToken(imageAsset);
		
		// sets direction randomly for token
		final Random generator = new Random();
		final double r = generator.nextDouble();
		
		if (r <= 0.5) {
			setAnchor(Stage.getWidth(), constantState);
			tDirection = -1;
		}
		else {
			setAnchor(0, constantState);
			tDirection = 1;
		}
	} // end of constructor
	
	
	// set token random height between branch and seesaw
	// tokens only move sideways
	// verticalState = VerticalState.NOT_MOVING;
	// horizontalState = beginningState;
	// leftLimit = (xProportion - HORIZONTAL_LIMIT_PROPORTION) * Stage.getWidth();
	// rightLimit = (xProportion + HORIZONTAL_LIMIT_PROPORTION) * Stage.getWidth();
	
	
	

	/**
	 * Move horizontally.
	 */
	public void moveHorizontally()
	{
		x.set(x.get() + (tSpeed * tDirection));
	}

	// tokens list by name, point value, speed
	/**
	 * Stats token.
	 * 
	 * @param tName
	 *            the t name
	 */
	public void statsToken(final String listName)
	{
		final String[][] tokenList = { /*{ "hayes", "50", ".009" },*/
				{ "Pikachu", "25", ".007" },
				{ "Bulbasaur", "10", ".003" },
				{ "Charmander", "10", ".003" },
				{ "Caterpie", "1", ".001" },
				{ "Weedle", "1", ".001" },
				{ "Meowth", "-5", ".003" },
				{ "TeamRocket", "-10", ".003" },
				{ "Snorlax", "0", ".003" },
				//{ "letterH", "2", ".006" },
				//{ "letterA", "2", ".006" },
				//{ "letterY", "2", ".006" },
				//{ "letterE", "2", ".006" },
				//{ "letterS", "2", ".006" }
				};
		
		for (int i = 0; i < tokenList.length; i++ )
		{
			if (listName.compareTo(tokenList[i][0]) == 0)
			{
				tName = tokenList[i][0];
				tPoint = Integer.parseInt(tokenList[i][1]);
				tSpeed = Double.parseDouble(tokenList[i][2]);
				i = tokenList.length;
			}
		}
		
	} // end statsToken
	
	// access to point value of token
	public int getPointValue() {
		return tPoint;
	}
	
	// access to name of token
	public String getTokenName() {
		return tName;
	}
	
	
} // end of class
